<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="box"></div>
		<script>
			var box = document.getElementById('box')
			var d = 0
			//距离2022年5月1日的倒计时
			function toTime() {
				var now = new Date()
				var target = new Date('2022/5/1')
				d = target - now
				var dd = parseInt(d / 1000 / 60 / 60 / 24)
				var hh = parseInt((d / 1000 / 60 / 60) % 24)
				var mm = parseInt((d / 1000 / 60) % 60)
				var ss = parseInt((d / 1000) % 60)
				var time = dd + '天' + hh + '时' + mm + '分' + ss + '秒'
				box.innerHTML = '距离2020年5月1号还剩 ' + time
			}
			setInterval(() => {
				toTime()
				if (d == 0) {
					box.innerHTML = '计时结束 '
				}
			}, 1000)
		</script>
	</body>
</body>
</html>